<?php

class Tracklist_Action_Default extends Kernel_Action_Form 
{
    
    /**
     * Path to the file template.
     *
     * @var string
     */
    protected $_template = 'tracklist/default.tpl';
    
    /**
     * Флаг, указывающий, что после сохранения данных формы не нужно показывать
     * сответствующее сообщение.
     *
     * @var boolean
     */
    protected $_no_message = true;
    
    /**
    * @desc Flag pointing out that after form submit page will self-redirect
    * 
    * @param boolean
    */
    protected $_self_redirect = false; 
    
    /**
    * Initialize form elements.
    * 
    */
    protected function _initElements() 
    {
        $this->_addElement('separator', array(
            'value' => '-'
        ));
        
        $this->_addElement('sequence', array(
            'type' => 'list', 
            'values' => array(
                Tracklist::SEQUENCE_ASC => 'Perfomer - Title', 
                Tracklist::SEQUENCE_DESC => 'Title - Perfomer', 
            )
        ));
        
        $this->_addElement('tracklist', array(
            'type' => 'file', 
            'validators' => array(
                array('file', array(
                    'type_allowed' => Kernel_Config::get('generator', 'type_allowed'), 
                ))
            )));    
        $this->_setAsRequired();
    }
    
    protected function _insert() 
    {
        Application::getResponse()->assign(array(
            'tracklist' => file($this->_getValue('tracklist')->getPath()), 
            'separator' => $this->_getValue('separator'), 
            'sequence' => $this->_getValue('sequence'), 
        ));
    }
    
}